the requested resource is not available [closed]
Posted
by
James Pj
on Programmers
See other posts from Programmers
or by James Pj
Published on 2012-12-15T10:36:04Z
Indexed on
2012/12/15
11:21 UTC
Read the original article
Hit count: 249
I have written a Java servlet program and run it through local Tomcat 7, But it was showing following error : HTTP Status 404 - /skypark/registration type Status report message /skypark/registration description The requested resource is not available. Apache Tomcat/7.0.33
I don't know what was the reason for it my Html page is
<html>
<head>
<title>
User registration
</title>
</head>
<body>
<form action="registration" method="post">
<center>
<h2><b>Skypark User Registration</b></h2>
<table border="0">
<tr><td>
First Name
</td><td>
<input type="text" name="fname"/></br>
</td></tr><tr><td>
Last Name
</td><td>
<input type="text" name="lname"/></br>
</td></tr><tr><td>
UserName
</td><td>
<input type="text" name="uname"></br>
</td></tr><tr><td>
Enter Password
</td><td>
<input type="password" name="pass"></br>
</td></tr><tr><td>
Re-Type Password
</td><td>
<input type="password" name="pass1"></br>
</td></tr><tr><td>
Enter Email ID
</td><td>
<input type="email" name="email1"></br>
</td></tr><tr><td>
Phone Number
</td><td>
<input type="number" name="phone">
</td></tr><tr><td>
Gender<br>
</td></tr><tr><td>
<input type="radio" name="gender" value="Male">Male</input></br>
</td></tr><tr><td>
<input type="radio" name="gender" value="Female">Female</input></br>
</td></tr><tr><td>
Enter Your Date of Birth<br>
</td><td>
<Table Border=0>
<tr>
<td>
Date
</td>
<td>Month</td>
<td>Year</td>
</tr><tr>
<td> <select name="date">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
.
.
.
have some code
.
.
.
</table>
<input type="submit" value="Submit"></br>
</center>
</form>
</body>
</html>
My servlet is :
package skypark;
import skypark.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Registration extends HttpServlet
{
public static Connection prepareConnection()throws ClassNotFoundException,SQLException
{
String dcn="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@JamesPJ-PC:1521:skypark";
String usname="system";
String pass="tiger";
Class.forName(dcn);
return DriverManager.getConnection(url,usname,pass);
}
public void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
{
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
try
{
String phone1,uname,fname,lname,dob,address,city,state,country,pin,email,password,gender,lang,qual,relegion,privacy,hobbies,fav;
uname=req.getParameter("uname");
fname=req.getParameter("fname");
lname=req.getParameter("lname");
dob=req.getParameter("date");
address=req.getParameter("address");
city=req.getParameter("city");
state=req.getParameter("state");
country=req.getParameter("country");
pin=req.getParameter("pin");
email=req.getParameter("email1");
password=req.getParameter("password");
gender=req.getParameter("gender");
phone1=req.getParameter("phone");
lang="";
qual="";
relegion="";
privacy="";
hobbies="";
fav="";
int phone=Integer.parseInt(phone1);
Connection con=prepareConnection();
String Query="Insert into regdetails values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(Query);
ps.setString(1,uname);
ps.setString(2,fname);
ps.setString(3,lname);
ps.setString(4,dob);
ps.setString(5,address);
ps.setString(6,city);
ps.setString(7,state);
ps.setString(8,country);
ps.setString(9,pin);
ps.setString(10,lang);
ps.setString(11,qual);
ps.setString(12,relegion);
ps.setString(13,privacy);
ps.setString(14,hobbies);
ps.setString(15,fav);
ps.setString(16,gender);
int c=ps.executeUpdate();
String query="insert into passmanager values(?,?,?,?)";
PreparedStatement ps1=con.prepareStatement(query);
ps1.setString(1,uname);
ps1.setString(2,password);
ps1.setString(3,email);
ps1.setInt(4,phone);
int i=ps1.executeUpdate();
if(c==1||c==Statement.SUCCESS_NO_INFO && i==1||i==Statement.SUCCESS_NO_INFO)
{
out.println("<html><head><title>Login</title></head><body>");
out.println("<center><h2>Skypark.com</h2>");
out.println("<table border=0><tr>");
out.println("<td>UserName/E-Mail</td>");
out.println("<form action=login method=post");
out.println("<td><input type=text name=uname></td>");
out.println("</tr><tr><td>Password</td>");
out.println("<td><input type=password name=pass></td></tr></table>");
out.println("<input type=submit value=Login>");
out.println("</form></body></html>");
}
else
{
out.println("<html><head><title>Error!</title></head><body>");
out.println("<center><b>Given details are incorrect</b>");
out.println(" Please try again</center></body></html>");
RequestDispatcher rd=req.getRequestDispatcher("registration.html");
rd.include(req,resp);
return;
}
}
catch(Exception e)
{
out.println("<html><head><title>Error!</title><body>");
out.println("<b><i>Unable to process try after some time</i></b>");
out.println("</body></html>");
RequestDispatcher rd=req.getRequestDispatcher("registration.html");
rd.include(req,resp);
return;
}
out.flush();
out.close();
}
}
And the web.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>skypark.Registration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>/registration</url-pattern>
</servlet-mapping>
This i kept in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\skypark\WEB_INF\web.xml
and servlet class in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\skypark\WEB_INF\classes\skypark
and registration.html in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\skypark\
if any mistake in this makes above error means please help me.Thanks in advance....
© Programmers or respective owner